package com.itfreer.special.report;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.dubbo.config.annotation.Service;
import com.itfreer.form.api.BaseDao;
import com.itfreer.form.api.DictionaryServiceImp;
import com.itfreer.form.api.dictionary.DictionaryEntity;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * 定义报表数据定义实现类
 */
@Component
@Service(interfaceClass = ReportDictionaryService.class, path = "reportdictionary")
public class ReportDictionaryServiceImp extends DictionaryServiceImp<ReportDictionaryEntity>
		implements ReportDictionaryService {

	@Autowired
	private ReportDictionaryDao dao;

	@Override
	protected BaseDao<ReportDictionaryEntity> getDao() {
		return dao;
	}

	@Override
	public String getDictionaryName() {
		return "report_dictionary";
	}

	@Override
	protected DictionaryEntity convert(ReportDictionaryEntity entity) {
		DictionaryEntity toEntity = new DictionaryEntity();
		toEntity.setDisplay(entity.getDataname());
		toEntity.setCode(entity.getId());
		BeanUtils.copyProperties(entity, toEntity);
		return toEntity;
	}

	@Override
	protected String getDictionaryFields() {
		return "*";
	}

	@Override
	public List<LinkedHashMap<String, Object>> getTableList(String tableName, String fieldName, String where) {
		if (null == tableName || "".equals(tableName)) {
			return null;
		}

		if (null == fieldName || "".equals(fieldName)) {
			return null;
		}
		return dao.getTableList(tableName, fieldName, where);
	}

	@Override
	public List<Map<String, Object>> getTableField(String tableName) {
		if (null == tableName || "".equals(tableName)) {
			return null;
		}
		return dao.getTableField(tableName);
	}
}
